<?php
require_once './start.php';

// 通用文件，包括配置、Xiaonei初始化等
require_once './common.php';

$user_info = mysql_fetch_array($user_result);
$money = $user_info['money'];

?>

      <!-- 创建一组标准的 Xiaonei 标签导航栏。 -->
      <div id="sub-nav">
      <ul>
        <li style="padding-right:10px;" ><a href="<? echo $config['app_app_url'] ?>index.php">送礼给他/她</a></li>
        <li style="padding-right:10px;"><a href="<? echo $config['app_app_url'] ?>send.php">送出的鲜花</a></li>
        <li style="padding-right:10px;"><a href="<? echo $config['app_app_url'] ?>receive.php">接收的鲜花</a></li>
        <li style="padding-right:10px;"><a href="<? echo $config['app_app_url'] ?>invite.php">邀请好友加入</a></li>
        <li style="padding-right:10px;" class="selected"><a href="<? echo $config['app_app_url'] ?>mine.php">我的账户</a></li>
      </ul>
      </div>

<?

//$order_id=sprintf("'%10.0f'\n", utime(1));
//$order_id=time();
$amount = $_GET['amount'];
$desc = "充值 $amount 元。";

  // 写数据库
  $conn = get_db_conn();
  $sql = "INSERT INTO `".$config['db_prefix']."orders` ( `pay_uid` , `pay_amt`, `desc`)
          VALUES ( '$uid', '$amount', '$desc');";
  if(!mysql_query($sql, $conn)) {
	echo message_box('数据库错误', "交易数据录入失败！", 'error');
	mysql_close($conn);
	exit();	
  }
  $order_id=mysql_insert_id($conn);
  mysql_close($conn);

// 获取订单token
try{
	$method="regOrder";
	$params['order_id']=$order_id;
	$params['amount']=$amount;
	$params['desc']=$desc;
	$paytoken=$my->api_client->pay($method,$params);
	$token=$paytoken[0];
	echo "<yk:redirect url=\"http://guanxi.koubei.com/apps/yk_xiaobei/expend.html?app_id=200189&order_id=".$order_id."&amount=".$amount."&token=".$token."&redirect_url=http://apps.guanxi.koubei.com/php_songli/payok.php\" />";
	exit();
	//print_R($paytoken);
}catch(Exception $ex){		
	echo message_box('API错误', $ex->getMessage(), 'error');
	exit();	
}

?>

<table class="editorkit" border="0" cellspacing="0" style="margin:0.7em 0;width:750px">
  <tr class="width_setter">
    <th style="width:10px"></th>
    <td>
      <br/>
      <h2>
		<form action="http://guanxi.koubei.com/apps/yk_xiaobei/expend.html" method="get">
		充值：<? echo $amount ?> 元。<INPUT TYPE="submit">
		<input type="hidden" name="app_id" value="200189"/>
		<input type="hidden" name="order_id" value="<? echo $order_id ?>"/>
		<input type="hidden" name="amount" value="<? echo $amount ?>"/>
		<input type="hidden" name="token" value="<? echo $token ?>"/>
		<input type="hidden" name="redirect_url" value="<? echo $config['app_app_url'] ?>mine.php"/>
		</form>
		</h2>
      <br/>
    </td>
  </tr>
</table>
<?
require_once './stop.php';
?>